package com.addplus.townmall.server.api.mapper.town;

import com.addplus.townmall.server.api.model.town.Coupon;
import com.addplus.townmall.server.api.model.town.FloorShop;
import com.addplus.townmall.server.api.model.town.ShopDiscountZone;
import com.addplus.townmall.server.api.model.town.expand.OptimalShopExpand;
import com.addplus.townmall.server.api.model.town.expand.ShopDiscountZoneExpand;
import com.addplus.townmall.server.api.model.town.expand.ShopProductExpand;
import com.addplus.townmall.server.api.model.town.expand.SpikeActiveExpand;
import com.addplus.townmall.server.api.utils.BaseAddMapper;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 * 楼层商品关联表 Mapper 接口
 * </p>
 *
 * @author zhangjiehang
 * @since 2018-08-27
 */
public interface FloorShopMapper extends BaseAddMapper<FloorShop> {

    @Select("select sdz.*,s.store_name " +
            "from floor_shop fs " +
            "inner JOIN shop_discount_zone sdz ON fs.shop_id = sdz.shop_product_id " +
            "inner JOIN store s ON sdz.store_id = s.id "+
            "where ${ew.sqlSegment}")
    List<ShopDiscountZoneExpand> getFloorShopDiscountZone(@Param("ew") Wrapper wrapper);

    @Select("select c.* " +
            "from floor_shop fs " +
            "inner JOIN coupon c ON fs.shop_id = c.id " +
            "where ${ew.sqlSegment}")
    List<Coupon> getFloorCoupon(@Param("ew") Wrapper wrapper);

    @Select("select sa.* " +
            "from floor_shop fs " +
            "inner JOIN spike_active sa ON fs.shop_id = sa.id " +
            "where ${ew.sqlSegment}")
    @Results({
            @Result(property = "spikeActiveShopList", column = "id",
                    many = @Many(select = "com.addplus.townmall.server.api.mapper.town.SpikeActiveShopMapper.getPcMainSpikeActiveShopByActive")
            )
    })
    SpikeActiveExpand getFloorSpikeActive(@Param("ew") Wrapper wrapper);

    @Select("select os.*,s.store_name " +
            "from floor_shop fs " +
            "inner JOIN optimal_shop os ON fs.shop_id = os.shop_product_id " +
            "inner JOIN store s ON os.store_id = s.id "+
            "where ${ew.sqlSegment}")
    List<OptimalShopExpand> getFloorOptimalShop(@Param("ew") Wrapper wrapper);

    @Select("SELECT f.id,f.floor_id,f.shop_id,s.store_name,p.shop_name,p.shop_describe,p.shop_seal_img,p.line_price,p.sale_price from floor_shop f LEFT JOIN shop_product p on p.id=f.shop_id LEFT JOIN store s on s.id=p.store_id WHERE f.floor_id=#{floorId} AND f.is_delete=0 ORDER BY f.gmt_modified DESC")
    List<ShopProductExpand> getAddFloorShopByFloorId(IPage page, @Param("floorId")Integer floorId);

    @Select("SELECT f.id,f.floor_id,f.shop_id,s.store_name,p.shop_name,p.shop_describe,p.shop_seal_img,p.line_price,p.sale_price from floor_shop f LEFT JOIN shop_product_fight p on p.id=f.shop_id LEFT JOIN store s on s.id=p.store_id WHERE f.floor_id=#{floorId} AND f.is_delete=0 ORDER BY f.gmt_modified DESC")
    List<ShopProductExpand> getAddFloorFightShopByFloorId(IPage page,@Param("floorId")Integer floorId);

    @Select("SELECT f.id,f.floor_id,f.shop_id,p.id as shop_id,p.`name` as spike_active_name,p.status,p.begin_date,p.end_date,p.img_pate from floor_shop f LEFT JOIN spike_active p on p.id=f.shop_id WHERE f.floor_id=#{floorId} AND f.is_delete=0 ORDER BY f.gmt_modified DESC")
    List<ShopProductExpand> getSpikeActiveByFloorId(IPage page,@Param("floorId")Integer floorId);

    @Select("SELECT f.id,f.floor_id,f.shop_id,s.store_name,p.* from floor_shop f LEFT JOIN coupon p on p.id=f.shop_id LEFT JOIN store s on s.id=p.store_id WHERE f.floor_id=#{floorId} AND f.is_delete=0 ORDER BY f.gmt_modified DESC")
    List<ShopProductExpand> getfloorCouponByFloorId(IPage page,@Param("floorId")Integer floorId);
}
